home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_se / bit_constant.e < prev    next >
Text File  |  2000-03-25  |  6KB  |  286 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class BIT_CONSTANT
  17.    --
  18.    -- For Manifest Constant BIT_N.
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.  
  23. creation make
  24.  
  25. feature
  26.  
  27.    start_position: POSITION;
  28.          -- Of the first bit.
  29.  
  30.    value: STRING;
  31.          -- Only '0' and '1'.
  32.  
  33.    result_type: TYPE_BIT_1;
  34.  
  35.    is_writable: BOOLEAN is false;
  36.  
  37.    is_current: BOOLEAN is false;
  38.  
  39.    is_manifest_string: BOOLEAN is false;
  40.  
  41.    is_manifest_array: BOOLEAN is false;
  42.  
  43.    is_result: BOOLEAN is false;
  44.  
  45.    is_void: BOOLEAN is false;
  46.  
  47.    use_current: BOOLEAN is false;
  48.  
  49.    is_static: BOOLEAN is false;
  50.  
  51.    is_pre_computable: BOOLEAN is false;
  52.  
  53.    can_be_dropped: BOOLEAN is true;
  54.  
  55.    c_simple: BOOLEAN is true;
  56.  
  57.    static_result_base_class: BASE_CLASS is
  58.       do
  59.          Result := small_eiffel.get_class(as_bit_n);
  60.       end;
  61.  
  62.    assertion_check(tag: CHARACTER) is
  63.       do
  64.       end;
  65.  
  66.    static_value: INTEGER is
  67.       do
  68.       end;
  69.  
  70.    isa_dca_inline_argument: INTEGER is
  71.       do
  72.       end;
  73.  
  74.    dca_inline_argument(formal_arg_type: TYPE) is
  75.       do
  76.       end;
  77.  
  78.    afd_check is
  79.       do
  80.       end;
  81.  
  82.    mapping_c_target(target_type: TYPE) is
  83.       do
  84.          mapping_c_arg(target_type);
  85.       end;
  86.  
  87.    mapping_c_arg(formal_arg_type: TYPE) is
  88.       do
  89.          compile_to_c;
  90.       end;
  91.  
  92.    collect_c_tmp is
  93.       do
  94.       end;
  95.  
  96.    compile_to_c is
  97.       do
  98.          if result_type.is_c_unsigned_ptr then
  99.             cpp.register_bit_constant(Current);
  100.          else
  101.             cpp.put_string(fz_0x);
  102.             cpp.put_string(hexa);
  103.          end;
  104.       end;
  105.  
  106.    c_declare_for_old is
  107.       do
  108.       end;
  109.  
  110.    compile_to_c_old is
  111.       do
  112.       end;
  113.  
  114.    compile_to_jvm_old is
  115.       do
  116.       end;
  117.  
  118.    compile_target_to_jvm, compile_to_jvm is
  119.       local
  120.          i, idx: INTEGER;
  121.          ca: like code_attribute;
  122.          cp: like constant_pool;
  123.       do
  124.          ca := code_attribute;
  125.          cp := constant_pool;
  126.          idx := cp.idx_class2(fz_java_util_bitset);
  127.          ca.opcode_new(idx);
  128.          ca.opcode_dup;
  129.          ca.opcode_push_integer(value.count);
  130.          idx := cp.idx_methodref3(fz_java_util_bitset,fz_35,fz_27);
  131.          ca.opcode_invokespecial(idx,0);
  132.          from
  133.             i := value.count;
  134.          until
  135.             i = 0
  136.          loop
  137.             if value.item(i) = '1' then
  138.                ca.opcode_dup;
  139.                ca.opcode_push_integer(i - 1);
  140.                idx := cp.idx_methodref3(fz_java_util_bitset,fz_a4,fz_27);
  141.                ca.opcode_invokevirtual(idx,-2);
  142.             end;
  143.             i := i - 1;
  144.          end;
  145.       end;
  146.  
  147.    jvm_branch_if_false: INTEGER is
  148.       do
  149.       end;
  150.  
  151.    jvm_branch_if_true: INTEGER is
  152.       do
  153.       end;
  154.  
  155.    compile_to_jvm_into(dest: TYPE): INTEGER is
  156.       do
  157.          Result := standard_compile_to_jvm_into(dest);
  158.       end;
  159.  
  160.    jvm_assign is
  161.       do
  162.       end;
  163.  
  164.    to_runnable(ct: TYPE): like Current is
  165.       local
  166.          ic: INTEGER_CONSTANT;
  167.       do
  168.          if result_type = Void then
  169.             !!ic.make(value.count,start_position);
  170.             !!result_type.make(start_position,ic);
  171.             result_type := result_type.to_runnable(ct);
  172.             result_type.run_class.set_at_run_time;
  173.             hexa := value.twin;
  174.             hexa.to_hexadecimal;
  175.          end;
  176.          Result := Current;
  177.       end;
  178.  
  179.    stupid_switch(r: ARRAY[RUN_CLASS]): BOOLEAN is
  180.       do
  181.          Result := true;
  182.       end;
  183.  
  184.    precedence: INTEGER is
  185.       do
  186.          Result := atomic_precedence;
  187.       end;
  188.  
  189.    bracketed_pretty_print, pretty_print is
  190.       do
  191.          fmt.put_string(value);
  192.          fmt.put_character('B');
  193.       end;
  194.  
  195.    print_as_target is
  196.       do
  197.          fmt.put_character('(');
  198.          pretty_print;
  199.          fmt.put_character(')');
  200.          fmt.put_character('.');
  201.       end;
  202.  
  203.    short is
  204.       local
  205.          i: INTEGER;
  206.       do
  207.          from
  208.             i := 1;
  209.          until
  210.             i > value.count
  211.          loop
  212.             short_print.a_character(value.item(i));
  213.             i := i + 1;
  214.          end;
  215.          short_print.a_character('B');
  216.       end;
  217.  
  218.    short_target is
  219.       do
  220.          bracketed_short;
  221.          short_print.a_dot;
  222.       end;
  223.  
  224. feature {C_PRETTY_PRINTER}
  225.  
  226.    c_define is
  227.       local
  228.          i, k, digit_nb: INTEGER;
  229.  
  230.       do
  231.          digit_nb := (1).object_size * 2;
  232.          k := hexa.count \\ digit_nb;
  233.          i := 1;
  234.          if k > 0 then
  235.             from
  236.                cpp.put_string(fz_0x);
  237.             until
  238.                k = 0
  239.             loop
  240.                cpp.put_character(hexa.item(i));
  241.                i := i + 1;
  242.                k := k - 1;
  243.             end;
  244.             cpp.put_character(',');
  245.          end;
  246.          from
  247.          until
  248.             i > hexa.count
  249.          loop
  250.             cpp.put_string(fz_0x);
  251.             from
  252.                k := digit_nb;
  253.             until
  254.                k = 0
  255.             loop
  256.                cpp.put_character(hexa.item(i));
  257.                i := i + 1;
  258.                k := k - 1;
  259.             end;
  260.             if i <= hexa.count then
  261.                cpp.put_character(',');
  262.             end;
  263.          end;
  264.       end;
  265.  
  266. feature {NONE}
  267.  
  268.    id: INTEGER;
  269.  
  270.    hexa: STRING;
  271.  
  272.    make(sp: like start_position; s: STRING) is
  273.       require
  274.          s /= Void
  275.          -- `s' contains only '0' and '1'.
  276.       do
  277.          start_position := sp;
  278.          value := s;
  279.       ensure
  280.          value.count = s.count
  281.       end;
  282.  
  283. end -- BIT_CONSTANT
  284.  
  285.  
  286.